package coder.nav.controller;

import coder.nav.common.JwtToken;
import coder.nav.common.R;
import coder.nav.model.bo.NavSaveCashBO;
import coder.nav.model.bo.NavCashQueryBO;
import coder.nav.model.vo.*;
import coder.nav.service.NavCashService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@Api(tags = "记账本")
@RestController
@RequestMapping("/cash")
public class NavCashController {

    @Autowired
    private NavCashService cashService;

    @JwtToken
    @ApiOperation("记账本-保存")
    @PostMapping("/save")
    public R<Integer> save(@Validated  @RequestBody NavSaveCashBO bo) {
        return new R<>(cashService.saveCash(bo));
    }

    @JwtToken
    @ApiOperation("记账本-删除")
    @DeleteMapping("/delete")
    public R<Integer> delete(@RequestParam("id") Long id) {
        return new R<>(cashService.deleteCash(id));
    }

    @JwtToken
    @ApiOperation("记账本-余额")
    @GetMapping("/getCash")
    public R<BigDecimal> getCash() {
        return new R<>(cashService.getCash());
    }

    @JwtToken
    @ApiOperation("记账本-收支")
    @PostMapping("/getSum")
    public R<BigDecimal> getSum(@Validated @RequestBody NavCashQueryBO bo) {
        return new R<>(cashService.getSum(bo));
    }

    @JwtToken
    @ApiOperation("记账本-日均")
    @PostMapping("/getAvg")
    public R<BigDecimal> getAvg(@Validated @RequestBody NavCashQueryBO bo) {
        return new R<>(cashService.getAvg(bo));
    }

    @JwtToken
    @ApiOperation("记账本-分页")
    @PostMapping("/getPage")
    public R<NavPageVO<NavCashVO>> getPage(@Validated @RequestBody NavCashQueryBO bo) {
        return new R<>(cashService.getCashPage(bo));
    }

    @JwtToken
    @ApiOperation("记账本-详情")
    @GetMapping("/getInfo")
    public R<NavCashVO> getInfo(@RequestParam("id") Long id) {
        return new R<>(cashService.getInfo(id));
    }

    @JwtToken
    @ApiOperation("支付渠道-下拉列表")
    @GetMapping("/getChannelList")
    public R<List<NavKeyValueVO<Integer, String>>> getChannelList() {
        return new R<>(cashService.getChannelList());
    }

    @JwtToken
    @ApiOperation("消费标识-下拉列表")
    @GetMapping("/getFlagList")
    public R<List<NavKeyValueVO<Integer, String>>> getFlagList() {
        return new R<>(cashService.getFlagList());
    }

    @JwtToken
    @ApiOperation("消费类型-下拉列表")
    @GetMapping("/getTypeList")
    public R<List<NavKeyValueVO<Integer, String>>> getTypeList() {
        return new R<>(cashService.getTypeList());
    }

    @JwtToken
    @ApiOperation("柱状图-数据")
    @PostMapping("/getChartBar")
    public R<NavChartBarVO> getChartBar(@Validated @RequestBody NavCashQueryBO bo) {
        return new R<>(cashService.getChartBar(bo));
    }

    @JwtToken
    @ApiOperation("线型图-数据")
    @PostMapping("/getChartLine")
    public R<NavChartLineVO> getChartLine(@Validated @RequestBody NavCashQueryBO bo) {
        return new R<>(cashService.getChartLine(bo));
    }

    @JwtToken
    @ApiOperation("饼状图-数据")
    @PostMapping("/getChartPie")
    public R<NavChartPieVO> getChartPie(@Validated @RequestBody NavCashQueryBO bo) {
        return new R<>(cashService.getChartPie(bo));
    }

    @JwtToken
    @ApiOperation("饼状图-收支")
    @PostMapping("/getChartPieSum")
    public R<NavChartPieVO> getChartPieSum(@Validated @RequestBody NavCashQueryBO bo) {
        return new R<>(cashService.getChartPieSum(bo));
    }

    @JwtToken
    @ApiOperation("雷达图-数据")
    @PostMapping("/getChartRadar")
    public R<NavChartRadarVO> getChartRadar(@Validated @RequestBody NavCashQueryBO bo) {
        return new R<>(cashService.getChartRadar(bo));
    }

}
